package com.kai.server.exception.factory;

/**
 * <p>Project: furina-tea-party </p>
 * <p>Description: </p>
 * <p>Copyright (c) 2024 Karrytech (Shanghai/Beijing) Co., Ltd.</p>
 * <p>All Rights Reserved.</p>
 *
 * @author <a href="mailto:zhangkai@karrytech.com">Zhang Kai</a>
 */

import java.util.concurrent.ThreadFactory;

/**
 * 配合异常处理器
 */
public class ExceptionHandlingThreadFactory implements ThreadFactory {
    private Thread.UncaughtExceptionHandler handler;
    public ExceptionHandlingThreadFactory(Thread.UncaughtExceptionHandler handler) {
        this.handler = handler;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        //在这里设置异常处理器
        thread.setUncaughtExceptionHandler(handler);
        return thread;
    }
}